﻿using System;

namespace SKBFirst
{
    public class Pagination
    {
        private readonly ITreeNode treeNode;

        private Pagination(ITreeNode treeNode)
        {
            this.treeNode = treeNode;
        }

        public static Pagination Create(string[] init, ITreeNode treeNode)
        {
            var length = init.Length;
            for (var i = 0; i < length; i++)
                treeNode.Add(int.Parse(init[i]));
            return new Pagination(treeNode);
        }

        public void Process(string command)
        {
            var splitCommand = command.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            switch (splitCommand[0])
            {
                case "+":
                    var number = int.Parse(splitCommand[1]);
                    treeNode.Add(number);
                    break;
                case "?":
                    var left = int.Parse(splitCommand[1]);
                    var right = int.Parse(splitCommand[2]);
                    treeNode.Slice(left, right);
                    break;
            }
        }
    }
}